package com.coze.lg.cozeagent.controller.oldtest;

import com.coze.lg.cozeagent.controller.AipSpeech;
import com.coze.lg.cozeagent.controller.SessionParent;
import com.coze.openapi.service.service.CozeAPI;

import javax.websocket.Session;
import java.io.IOException;
import java.nio.ByteBuffer;

public class SessionWebsocket extends SessionParent {
    private final Session session;
    public SessionWebsocket(AipSpeech aipSpeech, CozeAPI cozeAPI, Session session) {
        super(aipSpeech, cozeAPI);
        this.session = session;
    }

    @Override
    public void sessionParentWriteFunc(byte[] data) throws IOException {
        // 判断连接是否仍然有效
        if (session.isOpen()) {
            // 发送文本消息（同步发送）
            session.getBasicRemote().sendBinary(ByteBuffer.wrap(data));
            // 也可以使用异步发送（不阻塞当前线程）
            // session.getAsyncRemote().sendText(message);
        }
    }
}
